import binascii
import time

import serial

try:
    ser = serial.Serial("COM3", 9600, timeout=1)
    print("success")
    order = "02 09 B1 30 06 00 00 73 AA "
    byte_order = binascii.unhexlify(order.replace(" ", ""))
    ser.write(byte_order)
    while True:
        line = ser.read_all()
    #     # data = line.decode("utf8").strip()
        data = binascii.hexlify(line).decode('ascii')
        print("data", data)
        time.sleep(0.5)
        # ser.write(byte_order)
except Exception as e:
    print(str(e))
finally:
    if ser.is_open:
        ser.close()
        print("close")
